package biz.datalk.industrialland.common.json;

import com.google.gson.JsonParser;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;

import java.io.IOException;

/**
 *
 * 将部分json内容保留为字符串形式，不进行解析
 *
 * @author tarofang@163.com
 * @date 2024-01-17
 */
public class RawStringGsonAdapter extends TypeAdapter<String> {
    @Override
    public void write(JsonWriter out, String value) throws IOException {
        out.jsonValue(value);
    }

    @Override
    public String read(JsonReader in) throws IOException {
        // return new JsonParser().parse(in).toString();
        return JsonParser.parseReader(in).toString();
    }
}
